package com.shihb.structuralpatterns.flyweightpattern;

import java.util.HashMap;

/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/7/20 21:37
 */
public class WebsiteFactory {
  /**
   * 维护一个池容器
   */
  private HashMap<String,Website> websiteMap=new HashMap<>();
  /**
   * 从池中获取享元对象，如果没有则创建并放入池中
   */
  public Website getWebsite(String type){
    if(!websiteMap.containsKey(type)){
      Website concreteWebsite = new ConcreteWebsite(type);
      websiteMap.put(type,concreteWebsite);
    }
    return websiteMap.get(type);
  }

  public void printMapSize(){
    System.out.println(websiteMap.size());
  }
}
